<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('语文')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="commitExam()">
                <i class="fa fa-plus"></i> 提交
            </a>

        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>

<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var removeFlag = [[${@permission.hasPermi('monitor:job:remove')}]];
    var datas = [[${@dict.getType('sys_job_group')}]];
    var prefix = ctx + "exam/paper";

    $(function () {
        var options = {
            url: prefix + "/chinese/list",
            sortName: "createTime",
            sortOrder: "desc",
            modalName: "任务",

            columns: [
                {
                    title: '语文考试',
                    align: 'left',
                    formatter: function (value, row, index) {
                        var actions = [];
                        var seq = index + 1;
                        actions.push(
                            '<div class="panel panel-default">' +
                            '                      <div class="panel-heading panel-title">' +
                            '                         第 ' + seq + ' 题：' + row.ename + '' +
                            '                      <p id="' + row.eid + '" ></></div>' +
                            '                      <div class="panel-body col-lg-offset-1">' +
                            '                          <div class="item">' +
                            '                              <div class="radio">' +
                            '                                  <input id="' + row.eid + 'a"  name="' + row.eid + '" value="a" type="radio"   >' +
                            '                              </div>' +
                            '                              <label for="">' + row.ea + '</label>' +
                            '                          </div>' +
                            '                          <div class="item">' +
                            '                              <div class="radio">' +
                            '                                  <input id="' + row.eid + 'b" name="' + row.eid + '" value="b" type="radio"   >' +
                            '                              </div>' +
                            '                              <label for="">' + row.eb + '</label>' +
                            '                          </div>' +
                            '                              <div class="item">' +
                            '                                  <div class="radio">' +
                            '                                      <input id="' + row.eid + 'c" name="' + row.eid + '" value="c" type="radio"  >' +
                            '                                  </div>' +
                            '                                  <label for="">' + row.ec + '</label>' +
                            '                              </div>' +
                            '                              <div class="item">' +
                            '                                  <div class="radio">' +
                            '                                      <input id="' + row.eid + 'd" name="' + row.eid + '" value="d" type="radio"  >' +
                            '                                  </div>' +
                            '                                  <label for="">' + row.ed + '</label>' +
                            '                              </div>' +
                            '                      </div>' +
                            '                  </div> ');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);

        $(".fixed-table-pagination").remove()

    });

    /* 调度任务状态显示 */
    function statusTools(row) {
        if (row.status == 1) {
            return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="start(\'' + row.jobId + '\', \'' + row.jobGroup + '\')"></i> ';
        } else {
            return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="stop(\'' + row.jobId + '\', \'' + row.jobGroup + '\')"></i> ';
        }
    }

    /* 立即执行一次 */
    function run(jobId) {
        $.modal.confirm("确认要立即执行一次任务吗？", function () {
            $.operate.post(prefix + "/run", {"jobId": jobId});
        })
    }

    /* 调度任务-停用 */
    function stop(jobId, jobGroup) {
        $.modal.confirm("确认要停用任务吗？", function () {
            $.operate.post(prefix + "/changeStatus", {"jobId": jobId, "jobGroup": jobGroup, "status": 1});
        })
    }

    /* 调度任务-启用 */
    function start(jobId, jobGroup) {
        $.modal.confirm("确认要启用任务吗？", function () {
            $.operate.post(prefix + "/changeStatus", {"jobId": jobId, "jobGroup": jobGroup, "status": 0});
        })
    }

    /* 调度日志查询 */
    function jobLog(jobId) {
        var url = ctx + 'monitor/jobLog';
        if ($.common.isNotEmpty(jobId)) {
            url += '?jobId=' + jobId;
        }
        $.modal.openTab("调度日志", url);
    }

    /* cron表达式生成 */
    function commitExam(eid, opt) {

        var radioAll = $('input:radio:checked');
        var radioUncheckedAll = $('input[type=radio]:not(:checked)');
        if (radioAll == null) {
            confirm("请先答题！");
            return;
        }
        if (radioUncheckedAll.length / radioAll.length !== 3) {
            confirm("请先答题！");
            return;
        }
        var data = [];
        for (i = 0; i < radioAll.length; i++) {

            var myObject = new Object();
            myObject.eid = radioAll[i].name;
            myObject.uanswer = radioAll[i].value;
            data[i] = myObject;
        }
        data = {"resultList": data}
        $.ajax({
            url: prefix + "/chinese/result",
            type: "POST",
            dataType: "json",
            contentType: 'application/json',
            data: JSON.stringify(data),
            success: function (data) {
                console.log(data);
                var examScore = data.data.examScore;
                $.modal.alert("得分：" + examScore.score + "\n"
                    + "错误：" + examScore.errors + "\n");
                var resultList = data.data.resultList;
                for (i = 0; i < resultList.length; i++) {
                    var rowi = resultList[i];
                    if (rowi.upoint === 0) {
                        $("#" + rowi.eid).text("正确答案："+rowi.ranswer);
                        $("#" + rowi.eid).css("color","red");
                    }
                }
            }
        });
    }

</script>
</body>
</html>